package database;

import java.io.Serializable;

import javax.persistence.Embeddable;
import javax.persistence.ManyToOne;

/**
 * This class represent Supermarket for Hibernate ORM Library
 * @author Moshe Ronen, Lior Bunzl
 *
 */
@Embeddable
public class ProductSupermarketId implements Serializable
{
	private static final long serialVersionUID = 1L;
	private Product product;
    private Supermarket supermarket;
    
	@ManyToOne
	public Product getProduct()
	{
		return product;
	}
	
	public void setProduct(Product product)
	{
		this.product = product;
	}
	
	@ManyToOne
	public Supermarket getSupermarket()
	{
		return supermarket;
	}
	
	public void setSupermarket(Supermarket supermarket)
	{
		this.supermarket = supermarket;
	}
    
	public boolean equals(Object o)
	{
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
 
        ProductSupermarketId that = (ProductSupermarketId) o;
 
        if (product != null ? !product.equals(that.product) : that.product != null) return false;
        if (supermarket != null ? !supermarket.equals(that.supermarket) : that.supermarket != null)
            return false;
 
        return true;
    }
	
	public int hashCode()
	{
        int result;
        result = (product != null ? product.hashCode() : 0);
        result = 31 * result + (supermarket != null ? supermarket.hashCode() : 0);
        return result;
    }
}
